﻿using Company.Application.Share.Entities;
using Company.Application.Share.Models;
using Company.Core.Models;
using Prism.Events;
using Prism.Modularity;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Company.Shell.ViewModels
{
    internal class ShellViewModel
    {
        private IRegionManager RegionManager { get; }
        private IModuleManager ModuleManager { get; }
        private IEventAggregator EventAggregator { get; }
        public ShellViewModel(
            IRegionManager regionManager,
            IEventAggregator eventAggregator,
            IModuleManager moduleManager
            )
        {
            RegionManager = regionManager;
            ModuleManager = moduleManager;
            EventAggregator = eventAggregator;
            EventAggregator.GetEvent<LoginSuccessEvent>().Subscribe(OnLoginSuccess, ThreadOption.UIThread);
        }

        private void OnLoginSuccess(UserEntity user)
        {
            //加载主界面
            ModuleManager.LoadModule(Names.MainModule);
            RegionManager.RequestNavigate(Names.ShellRegion, Names.MainView);
            
        }
    }
}
